library(stringr)
require(devtools)
library(movAPA)

miner=read.table('BamBBAno_APA.CountMatrix.PA.PR.txt', header=T, stringsAsFactors = F)
miner=miner[, c(1,3)]
miner$feature_id=str_split_fixed(miner$feature_id,'_',4)
miner$feature_id=as.data.frame(miner$feature_id)
type=miner[, c(2)]
miner=cbind(miner$feature_id,type)
colnames(miner)=c('chr','start','end','strand','count')
miner=miner[miner$count>0,]

end=miner
start=miner
colnames(start)=c('chr','coord','end','strand','count')
colnames(end)=c('chr','start','coord','strand','count')
start=start[,c('chr','strand','coord','count')]
end=end[,c('chr','strand','coord','count')]
end=end[end$strand=="+",]
start=start[start$strand=="-",]
pac=rbind(end,start)

PACds=readPACds(pacFile=pac, colDataFile=NULL, noIntergenic=FALSE, PAname='PA')
fapath <-'/tmp/mm9/mm9.fa'
PACfiles=faFromPACds(PACds, bsgenome=fapath, what='updn', fapre='200nt', up=-100, dn=100, byGrp=NULL, chrCheck=FALSE)
pdf("test.pdf")
plotATCGforFAfile (PACfiles, ofreq=FALSE, opdf=FALSE, refPos=101, mergePlots = TRUE)
dev.off()
